package base;

import java.util.Random;

/**
 * Generate gauss number via the nextInt() method.
 * 
 * @author rweiller
 * 
 */
public class Gauss
{
	public Random	x;
	public Random	y;
	public int		m;
	public int		e;

	/**
	 * Create a gauss generator
	 * 
	 * @param seed_x the first seed
	 * @param seed_y the second seed
	 * @param m the medium
	 * @param e the deviation
	 * @throws IllegalArgumentException if m minor e
	 */
	public Gauss(int seed_x, int seed_y, int m, int e)
			throws IllegalArgumentException
	{
		this.x = new Random(seed_x);
		this.y = new Random(seed_y);
		if (m - e < 0)
			throw new IllegalArgumentException("Config file : m should be strictly higher than e");
		this.m = m;
		this.e = e;
	}

	/**
	 * Return the next gauss number
	 * 
	 * @return a gauss number
	 */
	public int nextInt()
	{
		int aNumber = 0;
		while (aNumber < 1)
		{
			aNumber = (int) Math.round(m + e * (Math.cos(2 * Math.PI * x.nextDouble()) * Math.sqrt(-2 * Math.log(y.nextDouble()))));
		}
		return aNumber;
	}
}
